
import sqlite3

class dbProcessor(): 
    dbname = ""
    dbtype = ""
    def __init__(self,name=":memory",type="sqlite3"):
        self.dbname=name
        self.dbtype = type
        if(self.dbtype == "sqlite3"):
            self.conn = sqlite3.connect(name)
    def delAllTable(self):
        resultsc = self.conn.cursor()
        results = self.select('''SELECT name FROM
            (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) 
            WHERE type='table' and name <> 'sqlite_sequence' ORDER BY name''')
        print len(results)
        for row in results:
            tablename = row[0]
            print tablename
            self.executeSQL(r"DROP TABLE '%s'"%tablename )
        
    def executeSQL(self,sql,options=()):
        c = self.conn.cursor()
        c.execute(sql,options)
        c.close()
    def select (self,sql,options=()):
        c = self.conn.cursor()
        c.execute(sql,options)
        result= [row for row in c]
        c.close()
        return result
    def clearTable (self,sql,table):
        self.execute("delete from ?",(table,))
    
    def close(self):
        self.conn.close()